package com.c5p1ng.groovy.controller;

import com.c5p1ng.groovy.bean.RuleEngineExecuteContext;
import com.c5p1ng.groovy.dto.RuleEngineDto;
import com.c5p1ng.groovy.service.GroovyScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GroovyEngineController {
    @Autowired
    private GroovyScriptService groovyScriptService;

    @PostMapping("/doHandler")
    public Object doHandler(@RequestBody RuleEngineDto ruleEngineDto) {
        RuleEngineExecuteContext context = ruleEngineDto.getRuleEngineExecuteContext();
        Object o = groovyScriptService.fragmentEval(context, ruleEngineDto.getStrategyId());
        return o;
    }

}
